# 捕获异常和超时处理
import requests

def test_status_code_with_timeout(code, timeout=5):
    url = f"https://httpbin.org/status/{code}"
    try:
        response = requests.get(url, timeout=timeout)
        print(f"Response received. Status code: {response.status_code}")
    except requests.exceptions.Timeout:
        print(f"Request timed out for status code: {code}")
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")

# 测试请求超时的情况
test_status_code_with_timeout(200, timeout=0.001)
test_status_code_with_timeout(200, timeout=2)
